package zhanglu.family.socket.demo.otherdemo.server;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

import zhanglu.family.socket.demo.otherdemo.TestBean;
import zhanglu.family.socket.util.JsonUtil;

/**
 * 总线消息解析器
 * 
 * @author zhanglu
 * @date 2017年3月10日
 */
public class ServerHandler extends IoHandlerAdapter {

    /**
     * messageReceived:当接收了一个消息时调用,这个也是最重要的
     */
    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {

        TestBean bean = (TestBean) JsonUtil.StringToOb(message, TestBean.class);
        if (bean.getType() == 1) {
            bean.setDes("我收到了啊");
            session.write(JsonUtil.ObToJsonStr(bean));
        }
    }
}
